import request from '@/utils/request'

import {
  getToken,
  setToken,
  removeToken
} from '@/utils/auth'

export function api_login(username, password, verificationCodeTag, verificationCode) {
  return request({
    url: '/web/system/user/login',
    method: 'post',
    data: {
      username: username,
      password: password,
      verificationCodeTag: verificationCodeTag,
      verificationCode: verificationCode
    }
  })
}

export function api_register(email, username, password, verificationCodeTag, verificationCode) {
  return request({
    url: '/web/system/user/register',
    method: 'post',
    data: {
      email: email,
      username: username,
      password: password,
      verificationCodeTag: verificationCodeTag,
      verificationCode: verificationCode
    }
  })
}


//验证token是否有效
export function api_verifyToken() {
  var Token = getToken();
  return request({
    url: '/web/system/user/verifyToken',
    method: 'get',
    params: {
      Token
    }
  })
}

//获取用户列表
export function api_userTable(query, pageNum, pageSize) {
  return request({
    url: '/web/system/user/table',
    method: 'get',
    params: {
      query,
      pageNum,
      pageSize
    }
  })
}

//获取用户详情
export function api_userInfo(uid) {
  return request({
    url: '/web/system/user/info',
    method: 'get',
    params: {
      uid
    }
  })
}

//设置用户详情
export function api_setUpdateUserInfo(uid, username, email, userRole, balance, userState, subTable) {
  return request({
    url: '/web/system/user/setUpdateUserInfo',
    method: 'post',
    data: {
      uid: uid,
      username: username,
      email: email,
      userRole: userRole,
      balance: balance,
      userState: userState,
      subTable: subTable
    }
  })
}

//获取用户详情
export function api_userLoaderConfig(uid) {
  return request({
    url: '/web/system/user/userLoaderConfig',
    method: 'get',
    params: {
      uid
    }
  })
}

//设置用户详情
export function api_userLoaderConfigUpdate(uid, loadLuaData, loadLuaStart) {
  return request({
    url: '/web/system/user/userLoaderConfigUpdate',
    method: 'post',
    data: {
      uid: uid,
      loadLuaData: loadLuaData,
      loadLuaStart: loadLuaStart
    }
  })
}
